<?php   
/** 
* The administration panel. Controller 
* Панель администрирования. Контроллер  
* @author IT studio IRBIS-team 
* @copyright © 2009 IRBIS-team 
*/ 
///////////////////////////////////////////////////////// 

/** 
* Generation of page of an error at access out of system 
* Генерация страницы ошибки при доступе вне системы 
*/ 
    if(!defined('IRB_KEY')) 
    { 
       header("HTTP/1.1 404 Not Found");       
       exit(file_get_contents('../../404.html')); 
    } 
//////////////////////////////////////////////////////////

/** 
* Function of generation of a menu of pages
* Функция генерации меню страниц
* @param array
* @return string
*/ 
    function createMenu($links = array())
    {
        if(count($links))
        {
            $menu = "<ul class=\"pages_menu\">\n";
            foreach($links as $num => $link)
                $menu .= "<li>
                          <input name=\"form[array1][]\" type=\"checkbox\" value=\"". $num ."\" />
                          <a href=\"". href('rem=edit', 'id='. $link[0], 'num='. $num) ."\">". $link[1] ."</a> 
                          </li>\n";
    
            return $menu ."</ul>\n";
         }    
    }
////////////////////////////////////////////////////////////////
       
    if(file_exists(IRB_ROOT .'setup/menu.txt'))
       $links = unserialize(file_get_contents(IRB_ROOT .'setup/menu.txt'));
    else
       $links = array();

/** 
* New page
* Новая страница 
*/     
    if($ok && $POST['value1'] && $POST['value2'])
    {
        $url = mb_strtolower($POST['value1']);
		$reserve = array();
		
		if(count($links))
		    foreach($links as $num => $link)
		        $reserve[] = $link[0];
			
		if(!preg_match("#^[a-z]+$#ui", $url))
            $info[] = IRB_INVALID_DATA;
		elseif(in_array($url, $reserve))
		    $info[] = IRB_DOUBLE_LINK;
        else
        {
            $keys = array_keys($links); 
            $id = max($keys) + 1;
            $links[$id] = array($url, htmlspecialchars($POST['value2']));
            
            file_put_contents(IRB_ROOT .'setup/'. $url .'.txt', '');
            file_put_contents(IRB_ROOT .'setup/menu.txt', serialize($links));        
    
            reDirect();    
        }     
    }
         
/** 
* Page removal 
* Удаление страницы 
*/             
    if($delete)
    {
        foreach($links as $num => $link)
            if(in_array($num, $POST['array1']))
                unlink(IRB_ROOT .'setup/'. $link[0] .'.txt');
            else
                $new_links[$num] = $link;    

        file_put_contents(IRB_ROOT .'setup/menu.txt', serialize($new_links));        

        reDirect();    
    }     
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
          
